﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vaffanculo.Data.Interfaces;
using System.Data.Entity;

namespace Vaffanculo.Data.Implements
{
    /// <summary>
    /// DbContext Adapter for support differents context (models/databases)
    /// </summary>
    public class DbContextAdap : IDbContext
    {
        private readonly DbContext _context;

        /// <summary>
        /// Constructor DbContextAdap.
        /// </summary>
        /// <typeparam name="DbContext">
        /// The DbContext type that requires a DbContext Adapter.
        /// </typeparam>
        public DbContextAdap(DbContext context)
        {
            _context = context;
        }

        /// <summary>
        /// Dispose of DbContext.
        /// </summary> 
        public void Dispose()
        {
            _context.Dispose();
        }

        #region IDbContext Members

        /// <summary>
        /// Set DbSet for mapped Objects to database.
        /// </summary>
        /// <typeparam name="TEntity">
        /// The entity mapped.
        /// </typeparam>
        /// <returns>IDbSet<TEntity></returns>
        public IDbSet<TEntity> Set<TEntity>() where TEntity : class
        {
            return _context.Set<TEntity>();
        }

        /// <summary>
        /// Save changes to database with DbContext.
        /// </summary> 
        /// <returns>int</returns>
        public int SaveChanges()
        {
            return _context.SaveChanges();
        }

        #endregion
    }
}
